//
// Created by 徐岩 on 2024/8/6.
//

#ifndef YOLOV8NCNN_JVMCALLBACK_H
#define YOLOV8NCNN_JVMCALLBACK_H

#include <android/log.h>
#include <jni.h>
#include "util.h"
#include "opencv2/core/mat.hpp"

#define MAIN_THREAD 0
#define CHILD_THREAD 1


#define max(x,y)  (x>y?x:y)
#define min(x,y)  (x<y?x:y)
#define y(r,g,b)  (((66 * r + 129 * g + 25 * b + 128) >> 8) + 16)
#define u(r,g,b)  (((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128)
#define v(r,g,b)  (((112 * r - 94 * g - 18 * b + 128) >> 8) + 128)
#define color(x)  ((unsigned char)((x < 0) ? 0 : ((x > 255) ? 255 : x)))

#define RGBA_YUV420SP   0x00004012
#define BGRA_YUV420SP   0x00004210
#define RGBA_YUV420P    0x00014012
#define BGRA_YUV420P    0x00014210
#define RGB_YUV420SP    0x00003012
#define RGB_YUV420P     0x00013012
#define BGR_YUV420SP    0x00003210
#define BGR_YUV420P     0x00013210

class JvmCallback {
public:
    _JavaVM *javaVM = NULL;
    JNIEnv *jniEnv = NULL;
    jobject jobj;
    jmethodID jmid_onCameraFrame;
    jmethodID jmid_onSaveYoloData;

public:
    JvmCallback(_JavaVM *javaVM, JNIEnv *jniEnv, jobject jobj);
    ~JvmCallback();
    void onCameraFrame(int type, unsigned char *data, int width,int height);
    void onCameraFrame(int type, cv::Mat &rgb);
    void rgbaToYuv(int, int, unsigned char*, unsigned char*, int);
    void onSaveYoloData(int type,const char* path_dir, const char *json);

};


#endif //YOLOV8NCNN_JVMCALLBACK_H
